package com.googlecode.chios.jnet.io;

import java.io.IOException;
import java.net.StandardSocketOptions;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.TimeUnit;

import com.googlecode.chios.jnet.buffer.ChannelBufferFactory;
import com.googlecode.chios.jnet.buffer.HeapChannelBufferFactory;
import com.googlecode.chios.jnet.codec.Decoder;
import com.googlecode.chios.jnet.codec.Encoder;
import com.googlecode.chios.jnet.handler.BussinessHandler;


/**
 * 
 * 配置信息
 * @author luzj
 *
 */
public class Configration {
	
	public boolean SO_REUSEADDR = true;
	
	public int SO_RCVBUFF = 16 * 1024;
	
	public int readBuffSize = 24 * 1024;
	
	public int writeBuffSize = 16 * 1024;
	
	public long timeout = TimeUnit.SECONDS.toMillis(1);

	public ChannelBufferFactory bufferFactory;
	
	public Decoder decoder;
	
	public Encoder encoder;

	public BussinessHandler bussinessHandler;
	
	public Configration() {
		bufferFactory = HeapChannelBufferFactory.getInstance();
	}

	public void config(AsynchronousSocketChannel channel) throws IOException {
		channel.setOption(StandardSocketOptions.SO_RCVBUF, SO_RCVBUFF);
	}

	public void config(AsynchronousServerSocketChannel serverChannel) throws IOException {
		serverChannel.setOption(StandardSocketOptions.SO_REUSEADDR, SO_REUSEADDR);
		serverChannel.setOption(StandardSocketOptions.SO_RCVBUF, SO_RCVBUFF);
	}
	
}
